using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;


namespace Entity
{
	/// <summary>
	/// This object represents the Private Fields of TblSalesPerson.
	/// </summary>
	
	[System.ComponentModel.DataObject]
    public class TblSalesPerson : DatabaseUtility
    {
		#region TblSalesPerson Private Fields


		Int32 _sPId;
		String _sPUserName = String.Empty;
		String _sPPassword = String.Empty;
		String _firstName = String.Empty;
		String _lastName = String.Empty;
		String _emailAddress = String.Empty;
		String _address1 = String.Empty;
		String _address2 = String.Empty;
		String _phoneNo = String.Empty;
		String _city = String.Empty;
		String _state = String.Empty;
		String _zip = String.Empty;
		String _country = String.Empty;
		DateTime _createDate;
		Boolean _isActive;
		Boolean _isDeleted;
		
		#endregion
		#region TblSalesPerson Constractor
		/// <summary>
        /// Creates an empty object of TblSalesPerson. 
        /// This is mainly used to create a new instance of TblSalesPerson to add a new TblSalesPerson.
        /// </summary>
		public TblSalesPerson(){}
		
				
		/// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblSalesPerson.
        /// </summary>
		public TblSalesPerson
		(
			Int32 sPId,
			String sPUserName,
			String sPPassword,
			String firstName,
			String lastName,
			String emailAddress,
			String address1,
			String address2,
			String phoneNo,
			String city,
			String state,
			String zip,
			String country,
			DateTime createDate,
			Boolean isActive,
			Boolean isDeleted
		)
		{
			_sPId = sPId;	
			_sPUserName = sPUserName;	
			_sPPassword = sPPassword;	
			_firstName = firstName;	
			_lastName = lastName;	
			_emailAddress = emailAddress;	
			_address1 = address1;	
			_address2 = address2;	
			_phoneNo = phoneNo;	
			_city = city;	
			_state = state;	
			_zip = zip;	
			_country = country;	
			_createDate = createDate;	
			_isActive = isActive;	
			_isDeleted = isDeleted;	
		}
		
		#endregion
		#region TblSalesPerson Properties
		
		 /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the SPId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_TblSalesPerson to update the data of an another TblSalesPerson instance.
        /// For view or updation purpose, every TblSalesPerson will be retrieved thru the proper 'Get' method.
        /// </summary>
		
		public Int32 SPId
		{
			get {return _sPId;}	
		}
		
				
		public String SPUserName
		{
			get {return _sPUserName;}
			set {_sPUserName = value;}
		}

		public String SPPassword
		{
			get {return _sPPassword;}
			set {_sPPassword = value;}
		}

		public String FirstName
		{
			get {return _firstName;}
			set {_firstName = value;}
		}

		public String LastName
		{
			get {return _lastName;}
			set {_lastName = value;}
		}

		public String EmailAddress
		{
			get {return _emailAddress;}
			set {_emailAddress = value;}
		}

		public String Address1
		{
			get {return _address1;}
			set {_address1 = value;}
		}

		public String Address2
		{
			get {return _address2;}
			set {_address2 = value;}
		}

		public String PhoneNo
		{
			get {return _phoneNo;}
			set {_phoneNo = value;}
		}

		public String City
		{
			get {return _city;}
			set {_city = value;}
		}

		public String State
		{
			get {return _state;}
			set {_state = value;}
		}

		public String Zip
		{
			get {return _zip;}
			set {_zip = value;}
		}

		public String Country
		{
			get {return _country;}
			set {_country = value;}
		}

		public DateTime CreateDate
		{
			get {return _createDate;}
			set {_createDate = value;}
		}

		public Boolean IsActive
		{
			get {return _isActive;}
			set {_isActive = value;}
		}

		public Boolean IsDeleted
		{
			get {return _isDeleted;}
			set {_isDeleted = value;}
		}
		

		#endregion
		#region TblSalesPerson Static Methods
		/************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
		/************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static  Int32 CreateNewTblSalesPerson
		(
			String sPUserName,
			String sPPassword,
			String firstName,
			String lastName,
			String emailAddress,
			String address1,
			String address2,
			String phoneNo,
			String city,
			String state,
			String zip,
			String country,
			DateTime createDate,
			Boolean isActive,
			Boolean isDeleted
		)
		{
			//creating an empty TblSalesPerson object
            TblSalesPerson tblSalesPerson = new TblSalesPerson();
				tblSalesPerson.SPUserName = sPUserName;
				tblSalesPerson.SPPassword = sPPassword;
				tblSalesPerson.FirstName = firstName;
				tblSalesPerson.LastName = lastName;
				tblSalesPerson.EmailAddress = emailAddress;
				tblSalesPerson.Address1 = address1;
				tblSalesPerson.Address2 = address2;
				tblSalesPerson.PhoneNo = phoneNo;
				tblSalesPerson.City = city;
				tblSalesPerson.State = state;
				tblSalesPerson.Zip = zip;
				tblSalesPerson.Country = country;
				tblSalesPerson.CreateDate = createDate;
				tblSalesPerson.IsActive = isActive;
				tblSalesPerson.IsDeleted = isDeleted;
			
			return TblSalesPerson.CreateNewTblSalesPerson(tblSalesPerson);
		}
	
		/************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool UpdateTblSalesPerson
		(
			Int32 sPId,
			String sPUserName,
			String sPPassword,
			String firstName,
			String lastName,
			String emailAddress,
			String address1,
			String address2,
			String phoneNo,
			String city,
			String state,
			String zip,
			String country,
			DateTime createDate,
			Boolean isActive,
			Boolean isDeleted
		)
		{
			 TblSalesPerson tblSalesPerson =  TblSalesPerson.GetTblSalesPersonBySPId(sPId);
			
				tblSalesPerson.SPUserName = sPUserName;
				tblSalesPerson.SPPassword = sPPassword;
				tblSalesPerson.FirstName = firstName;
				tblSalesPerson.LastName = lastName;
				tblSalesPerson.EmailAddress = emailAddress;
				tblSalesPerson.Address1 = address1;
				tblSalesPerson.Address2 = address2;
				tblSalesPerson.PhoneNo = phoneNo;
				tblSalesPerson.City = city;
				tblSalesPerson.State = state;
				tblSalesPerson.Zip = zip;
				tblSalesPerson.Country = country;
				tblSalesPerson.CreateDate = createDate;
				tblSalesPerson.IsActive = isActive;
				tblSalesPerson.IsDeleted = isDeleted;
			
			return TblSalesPerson.UpdateTblSalesPerson(tblSalesPerson);
		}

		/************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool DeleteTblSalesPerson
		(
			Int32 sPId
		)
		{
			//Validate Input
			if(sPId <= GetSPIdMinValue)
				throw (new ArgumentOutOfRangeException("sPId"));
				
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
			AddParameterToSqlCmd(sqlCmd, "@SPId",SqlDbType.Int, 0, ParameterDirection.Input, sPId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_DELETETBLSALESPERSON);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
			
		}
		
		/// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
		public static bool DeleteTblSalesPersonList( System.Collections.Generic.List<Int32>  sPIdListToDelete)
		{
			//Validate Input
			foreach (Int32 sPId in sPIdListToDelete)
			    if(sPId <= GetSPIdMinValue)
					throw (new ArgumentOutOfRangeException("sPId"));
			
			//performing deletion operation //

            string xmlString = FormatXMLForIdArray(sPIdListToDelete);
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@SPIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_DELETETBLSALESPERSONLIST);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == sPIdListToDelete.Count ? true : false);
		}
		
		/************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
		public static TblSalesPerson GetTblSalesPersonBySPId(Int32 sPId)
		{
			if(sPId <= GetSPIdMinValue)
					throw (new ArgumentOutOfRangeException("sPId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@SPId",SqlDbType.Int, 0, ParameterDirection.Input, sPId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_GETTBLSALESPERSONBYSPID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSalesPersonCollectionFromReader);
            CustomCollection<TblSalesPerson> objCollection = ((CustomCollection<TblSalesPerson>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
		}
		
		/************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/
		
		/************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblSalesPerson> GetAllTblSalesPerson()
		{
		
		 	// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_GETALLTBLSALESPERSON);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSalesPersonCollectionFromReader);
            CustomCollection<TblSalesPerson> objCollection = ((CustomCollection<TblSalesPerson>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
		}
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblSalesPerson> GetAllTblSalesPersonPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "SPId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_GETALLTBLSALESPERSONPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSalesPersonCollectionFromReader);
            CustomCollection<TblSalesPerson> objCollection = ((CustomCollection<TblSalesPerson>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblSalesPersonPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_GETALLTBLSALESPERSONPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		#endregion
		#region Employee Instance Methods
		/************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
		/// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
		public bool Save()
		{
			if(SPId<= GetSPIdMinValue)
			{
				Int32 TempId=CreateNewTblSalesPerson(this);
				if(TempId>0)
				{
					_sPId=TempId;
					return true;
				}
				else
				{
					// error occurs
					return false;
				}
			}
			else
			{	//This is a update Command
				return (UpdateTblSalesPerson(this));
			}
			
		}
		
		public static Int32 CreateNewTblSalesPerson(TblSalesPerson newTblSalesPerson)
		{
			// validate Parameters
			if (newTblSalesPerson == null)
				throw (new ArgumentNullException("newTblSalesPerson"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@SPUserName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSalesPerson.SPUserName);
			AddParameterToSqlCmd(sqlCmd, "@SPPassword",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.SPPassword);
			AddParameterToSqlCmd(sqlCmd, "@FirstName",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.FirstName);
			AddParameterToSqlCmd(sqlCmd, "@LastName",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.LastName);
			AddParameterToSqlCmd(sqlCmd, "@EmailAddress",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.EmailAddress);
			AddParameterToSqlCmd(sqlCmd, "@Address1",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.Address1);
			AddParameterToSqlCmd(sqlCmd, "@Address2",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.Address2);
			AddParameterToSqlCmd(sqlCmd, "@PhoneNo",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.PhoneNo);
			AddParameterToSqlCmd(sqlCmd, "@City",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.City);
			AddParameterToSqlCmd(sqlCmd, "@State",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.State);
			AddParameterToSqlCmd(sqlCmd, "@Zip",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.Zip);
			AddParameterToSqlCmd(sqlCmd, "@Country",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.Country);
			AddParameterToSqlCmd(sqlCmd, "@CreateDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblSalesPerson.CreateDate);
			AddParameterToSqlCmd(sqlCmd, "@IsActive",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSalesPerson.IsActive);
			AddParameterToSqlCmd(sqlCmd, "@IsDeleted",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSalesPerson.IsDeleted);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_CREATENEWTBLSALESPERSON);
			ExecuteScalarCmd(sqlCmd);
			return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

		}
		/// <summary>
        /// Updates an TblSalesPerson instance to the database.
        /// </summary>
		public static bool UpdateTblSalesPerson(TblSalesPerson newTblSalesPerson)
		{
			// validate Parameters
			if (newTblSalesPerson == null)
				throw (new ArgumentNullException("newTblSalesPerson"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@SPId",SqlDbType.Int, 0, ParameterDirection.Input, newTblSalesPerson.SPId);
			AddParameterToSqlCmd(sqlCmd, "@SPUserName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSalesPerson.SPUserName);
			AddParameterToSqlCmd(sqlCmd, "@SPPassword",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.SPPassword);
			AddParameterToSqlCmd(sqlCmd, "@FirstName",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.FirstName);
			AddParameterToSqlCmd(sqlCmd, "@LastName",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.LastName);
			AddParameterToSqlCmd(sqlCmd, "@EmailAddress",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.EmailAddress);
			AddParameterToSqlCmd(sqlCmd, "@Address1",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.Address1);
			AddParameterToSqlCmd(sqlCmd, "@Address2",SqlDbType.NVarChar, 200, ParameterDirection.Input, newTblSalesPerson.Address2);
			AddParameterToSqlCmd(sqlCmd, "@PhoneNo",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.PhoneNo);
			AddParameterToSqlCmd(sqlCmd, "@City",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.City);
			AddParameterToSqlCmd(sqlCmd, "@State",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.State);
			AddParameterToSqlCmd(sqlCmd, "@Zip",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.Zip);
			AddParameterToSqlCmd(sqlCmd, "@Country",SqlDbType.NVarChar, 50, ParameterDirection.Input, newTblSalesPerson.Country);
			AddParameterToSqlCmd(sqlCmd, "@CreateDate",SqlDbType.DateTime, 0, ParameterDirection.Input, newTblSalesPerson.CreateDate);
			AddParameterToSqlCmd(sqlCmd, "@IsActive",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSalesPerson.IsActive);
			AddParameterToSqlCmd(sqlCmd, "@IsDeleted",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSalesPerson.IsDeleted);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSALESPERSON_UPDATETBLSALESPERSON);
            ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
		}
		#endregion
		
		#region TblSalesPerson Related Collections
		/// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
		public static CollectionBase  GenerateTblSalesPersonCollectionFromReader(IDataReader returnData) 
		{
			
			//creating the instance of Employee collection
			CustomCollection<TblSalesPerson> colTblSalesPerson = new CustomCollection<TblSalesPerson>();
			
			/************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

			//getting the Employee collection by iterating thru the data reader
			while (returnData.Read()) 
			{
				//passing the TblSalesPerson constructor parameters from the current instance of data reader fields.
				TblSalesPerson newTblSalesPerson = new TblSalesPerson
				(
					returnData["SPId"]== System.DBNull.Value ? GetSPIdMinValue : (Int32 ) returnData["SPId"],
					returnData["SPUserName"]== System.DBNull.Value ? string.Empty: (String ) returnData["SPUserName"],
					returnData["SPPassword"]== System.DBNull.Value ? string.Empty: (String ) returnData["SPPassword"],
					returnData["FirstName"]== System.DBNull.Value ? string.Empty: (String ) returnData["FirstName"],
					returnData["LastName"]== System.DBNull.Value ? string.Empty: (String ) returnData["LastName"],
					returnData["EmailAddress"]== System.DBNull.Value ? string.Empty: (String ) returnData["EmailAddress"],
					returnData["Address1"]== System.DBNull.Value ? string.Empty: (String ) returnData["Address1"],
					returnData["Address2"]== System.DBNull.Value ? string.Empty: (String ) returnData["Address2"],
					returnData["PhoneNo"]== System.DBNull.Value ? string.Empty: (String ) returnData["PhoneNo"],
					returnData["City"]== System.DBNull.Value ? string.Empty: (String ) returnData["City"],
					returnData["State"]== System.DBNull.Value ? string.Empty: (String ) returnData["State"],
					returnData["Zip"]== System.DBNull.Value ? string.Empty: (String ) returnData["Zip"],
					returnData["Country"]== System.DBNull.Value ? string.Empty: (String ) returnData["Country"],
					returnData["CreateDate"]== System.DBNull.Value ? DateTime.MinValue: (DateTime ) returnData["CreateDate"],
					returnData["IsActive"]== System.DBNull.Value ? false: (Boolean ) returnData["IsActive"],
					returnData["IsDeleted"]== System.DBNull.Value ? false: (Boolean ) returnData["IsDeleted"]

				);
				//adding the Employee to the collection
				colTblSalesPerson.Add(newTblSalesPerson);
			}
			
			//returns the collection of Companys 
			return (colTblSalesPerson);
		}
		
		#endregion
		#region Constants and Default Values
		
		public static Int32 GetSPIdMinValue
		{
			get
			{
				return 0;
			}
		}
		
		//create method related contants
			internal const string SPR_TBLSALESPERSON_CREATENEWTBLSALESPERSON="spr_TblSalesPerson_CreateNewTblSalesPerson";
			internal const string SPR_TBLSALESPERSON_UPDATETBLSALESPERSON="spr_TblSalesPerson_UpdateTblSalesPerson";
			internal const string SPR_TBLSALESPERSON_DELETETBLSALESPERSON="spr_TblSalesPerson_DeleteTblSalesPerson";
			internal const string SPR_TBLSALESPERSON_DELETETBLSALESPERSONLIST="spr_TblSalesPerson_DeleteTblSalesPersonList";
			internal const string SPR_TBLSALESPERSON_GETTBLSALESPERSONBYSPID="spr_TblSalesPerson_GetTblSalesPersonBySPId";
			internal const string SPR_TBLSALESPERSON_GETALLTBLSALESPERSON="spr_TblSalesPerson_GetAllTblSalesPerson";
			internal const string SPR_TBLSALESPERSON_GETALLTBLSALESPERSONPAGED="spr_TblSalesPerson_GetAllTblSalesPersonPaged";
			internal const string SPR_TBLSALESPERSON_GETALLTBLSALESPERSONPAGEDCOUNT="spr_TblSalesPerson_GetAllTblSalesPersonPagedCount";
		
		#endregion
	}
}	
